#include<stdio.h>
#define numn 10010
#define numm 100100
long n,m,b,e,trace[numn],h[numn],a[numm][2],i,visited[numn],c[numm],queue[numn];
void input(){
    long i,u;
    FILE *fp=stdin;
    fscanf(fp,"%ld%ld%ld%ld",&n,&m,&b,&e);
    for(i=0;i<=n;i++)h[i]=0;
    for(i=1;i<=m;i++){
        fscanf(fp,"%ld%ld",&a[i][0],&a[i][1]);
        h[a[i][0]]++;
    }
    for(i=1;i<=n;i++)h[i]+=h[i-1];
    for(i=1;i<=m;i++)
        c[h[a[i][0]]--]=a[i][1];
    h[n+1]=m;
}
long bfs(long x){
    long u,v,left=0,right=0;
    queue[++right]=b;
    visited[b]=1;
    for(i=1;i<=n;i++)visited[i]=0;
    do{
        u=queue[++left];
        for(v=h[u]+1;v<=h[u+1];v++)
            if(c[v]!=x && visited[c[v]]==0){
                visited[c[v]]=1;
                queue[++right]=c[v];
                if(x==0)trace[c[v]]=u;
                if(c[v]==e)return 1;
            }
    }while(left<right);
    return 0;
}
long counting(){
    long v,count=0;
    bfs(0);
    v=trace[e];
    if(v==0)return 0;
    while(v!=b){
        if(!bfs(v))count++;
        v=trace[v];
    }
    return count;
}
int main(){
    input();
    printf("%ld",counting());
    return 0;
}
